﻿hpxAdminApp.factory('messageService', ['Restangular', '$interval', '$rootScope', '$state', '$cookieStore', function (Restangular, $interval, $rootScope, $state, $cookieStore) {
    var res = Restangular.all('backs');
    return {
        
        // 查找符合条件的客户
        findAllMessage: function (params, keyworld, locationld, person, personLevelId, htraderLevelCode, hbillTypeId, deadlineTime3, deadlineTime4, deadlineTime1, deadlineTime2) {
            var queryParam = {
                'p': params.page(),
                'n': params.count(),
                'orderBy': params.orderBy(),
                'keyworld': keyworld,
                'billTypeId': hbillTypeId,
                'traderLevelCode': htraderLevelCode,
                'locationld': locationld,
                'customerLevelId': personLevelId,
                'customerTypeCode': person,
                'offerTimeS': deadlineTime1,
                'offerTimeB': deadlineTime2,
                'signupTimeS': deadlineTime3,
                'signupTimeB': deadlineTime4
            }
            return res.get('message', queryParam).then(function (result) {
                params.total(result.page_info.items_number);
                return result.customer;
            });
        },
        sendMessage:function(model){
            console.log(model)
            return res.all('message').one('sendMessage').customPOST(model);
        },


        // 判断是否有使用权限 
        customerPrivilege: function (model) {
            //console.log(model)
            return res.all('customerPrivilege').post(model)
        },
        // 查询套餐
        privilegePackage: function (model) {
            return res.all('privilegePackage').post(model)
        },
        // 购买套餐
        privilegePackOrder: function (model) {
            return res.all('privilegePackOrder').post(model)
        },


        //customerLogout: function () {
        //    return res.all('customerLogout').post();
        //},
        //phoneVerify: function (phone) {
        //    return res.all('phoneVerify').one(phone.toString()).get();
        //},
        //customerPhone: function (data) {
        //    return res.one('customerPhone').customPUT(data);
        //},
        //customerReg: function (model) {
        //    return res.all('customerReg').post(model);
        //},
        //customerPasswordReset: function (phone, model) {
        //    console.log(model)
        //    return res.customPUT(model, 'customerPasswordReset', { 'phone': phone, 'r': 2 });
        //},
        //customerPasswordResets: function (phone, model) {
        //    console.log(model)
        //    return res.customPUT(model, 'customerPasswordReset', { 'phone': phone, 'r': 1 });
        //},
        //customerModifyPassword: function (model) {
        //    return res.one('customerPassword').customPUT(model);
        //},

        //getAllCustomerAddress: function () {
        //    return res.get('customerAddress', {});
        //},
        //getCustomerAddress: function (customerAddressId) {
        //    return res.all('customerAddress').one(customerAddressId.toString()).get();
        //},
        //addAddress: function (model) {
        //    return res.all('customerAddress').post(model);
        //},
        //updateAddress: function (model) {
        //    return res.one('customerAddress', model.id).customPUT(model);
        //},
        //updateAddressDefault: function (data) {
        //    return res.one('customerAddress').customPUT({}, data.id, { 'func': 'default' });
        //},

        //removeAddress: function (id) {
        //    return res.all('customerAddress').customDELETE(id);
        //},
        //getAllEnterpriseAccount: function (accountTypeCode) {
        //    return res.get('enterpriseAccount', { 'accountTypeCode': accountTypeCode });
        //},
        //getEnterpriseAccount: function (accountId) {
        //    return res.all('enterpriseAccount').one(accountId.toString()).get();
        //},
        //getAllEnterprise: function () {
        //    return res.get('enterprise', {});
        //},
        //getEnterprise: function (enterpriseId) {
        //    return res.all('enterprise').one(enterpriseId.toString()).get();
        //},
        //insertEnterprise: function (model) {
        //    return res.all('enterprise').post(model);
        //},
        //updateEnterprise: function (model) {
        //    return res.one('enterprise').customPUT(model);
        //},
        //deleteEnterprise: function (enterpriseId) {
        //    return res.all('enterprise').customDELETE(enterpriseId);
        //},
        //updateEnterpriseDefault: function (data) {
        //    return res.one('enterpriseAccount').customPUT({}, data.id, { 'func': 'default' });
        //},

        //updateEnterpriseCredential: function (model) {
        //    return res.one('enterpriseCredential', model.id).customPUT(model);
        //},

        //sendCustomerReview: function () {
        //    return res.one('customerReview').post();
        //},

        //getEnterpriseMember: function () {
        //    return res.get('enterpriseMember', {});
        //},
        //insertEnterpriseMember: function (model) {
        //    return res.all('enterpriseMember').post(model);
        //},
        //deleteEnterpriseMember: function (operater) {
        //    return res.all('enterpriseMember').customDELETE(operater.remove_phone_number, { 'code': operater.operator_phone_number_code });
        //},
        //insertEnterpriseAccount: function (model) {
        //    return res.all('enterpriseAccount').post(model);
        //},
        //updateWnterpriseAccount: function (model) {
        //    return res.all('enterpriseAccount').one(model.id.toString()).customPUT(model);
        //},
        //deleteEnterpriseAccount: function (enterpriseId) {
        //    return res.all('enterpriseAccount').customDELETE(enterpriseId);
        //},

        //getCustomer: function () {
        //    return res.get('customer', {});
        //},
        //updateCustomer: function (model) {
        //    return res.one('customer').customPUT(model);
        //},
        //verify: function (id, verify_string) {
        //    return res.one('enterpriseAccountCheck', id.toString()).customPUT({ 'verify_string': verify_string }, '', { 'func': 'auto' });
        //},
        //enterpriseDetail: function (keyword, is_simple) {
        //    return res.get("enterpriseDetail", { 'isSimple': is_simple, 'keyword': keyword });
        //},
        //testPhoneNumber: function (phone) {
        //    return res.get("testPhoneNumber", { 'phone': phone });
        //}
    }
}]);
